<?php
require_once('../includes/init.php');
$domain = "https://www.pentalink.com";
?>
<?php include('./header.php');?>
<?php
$cateId = $_GET["cate_id"];
if(empty($cateId) || $cateId == 0){
    $cateId = 15;
}

$page = $_GET["page"];
if(empty($page)){
    $page = 1;
}
$page_size = $_GET["page_size"];
if(empty($page_size)){
    $page_size = 8;
}

$cateInfo = $db->getRow("select * from `article_cate` where `cate_id` = $cateId");
if(empty($cateInfo)){
    $cateInfo["cate_name"] = "全部分类";
}
$offset = ($page-1) * $page_size;

$conditions = "";
$conditions .= "is_del = 0";
if(!empty($cateId) || $cateId > 0){
    $conditions .= " and cate_id = $cateId";
}

$sql = "SELECT *,if(`sort_order` > '0',1,0) AS `is_order` FROM `article` WHERE ".$conditions." ORDER BY  `is_order` DESC,`sort_order`, `update_tm` DESC, `article_id` DESC LIMIT $page_size offset $offset";
$article_list = $db->getAll($sql);

$sql1 = "SELECT count(*) FROM `article` WHERE ".$conditions.";";
$totalCount = $db->getOne($sql1);

$totalCount = $totalCount;
$data = array(
    'totalCount'	=> $totalCount,
    'pageSize'		=> $page_size,
    'currentPage'	=> $page
);
$pageCount = ceil($totalCount/$pageSize);
$pager = create_pages_new($data, $_GET, true);

//右侧新闻列表
$sql = "SELECT * FROM `article` order by click_count desc limit 5";
$hotNews = $db->getAll($sql);

//文章标签
$sql = "SELECT * FROM `article_cate` where is_del = 0";
$cates = $db->getAll($sql);

$_GET["from_page"] = "news";
?>
            <!-- 头部搜索框以及导航栏 -->
            <div class="header_div">
                <?php include('./common/search.php');?>
                <?php include('./common/nav.php');?>
            </div>
 
            <!-- 标签 -->
            <div class="post_position">
                <span class="home_span"><a href="./index.php">首页</a> > </span>
                <span><a>行业资讯</a></span>
            </div>

            <div class="news_content">
                <div class="common-layout-left news_content_info box">
                    <div class="secon_label_tag box">
                        <ul>
                            <?php if(in_array($cateId, [19, 10, 14])): ?>
                            <a href="./news.php?cate_id = 19"><li <?php if ($cateId == 19): ?> class="secon_label_tag_active" <?php endif; ?>>分享案例</li></a>
                            <a href="./news.php?cate_id=14" href=""><li <?php if ($cateId == 14): ?> class="secon_label_tag_active" <?php endif; ?>>技术文章</li></a>
                            <a href="./news.php?cate_id=10" href=""><li <?php if ($cateId == 10): ?> class="secon_label_tag_active" <?php endif; ?>>新品上市</li></a>
                            <?php else: ?>
                                <a><li class="secon_label_tag_active"><?php echo $cateInfo["cate_name"]; ?></li></a>
                            <?php endif; ?>

                        </ul>
                    </div>
                    <!-- 咨讯列表 -->
                    <div class="news_list">
                        <ul class="box">
                            <?php
                            if(!empty($article_list)):
                            foreach($article_list as $key => $list):
                            ?>

                                <li>
                                    <a style="display: inherit;" href="/new/newsdetail.php?id=<?php echo $list['article_id'];?>" title="<?php echo $list['title'];?>">
                                        <div class="news_list_img">
                                            <img src="/upload/<?php echo $list['pic'];?>" alt="<?php echo $list['title'];?>">
                                        </div>
                                    
                                        <div class="news_list_menu">
                                            <h3 class="ellipsis"><?php echo $list['title'];?></h3>
                                            <p class="con many_line line_two" style="min-width: 400px;"><?php echo $list['description'];?></p>
                                            <div class="news_guishuflei">
                                                <!-- <p><span>归属分类</p> -->
                                            </div>
                                            <div class="news_tip">
                                                <span>编辑：<?php echo $list["update_man"]; ?></span>
                                                <span class="time"><?php echo $list["update_tm"]; ?></span>
                                                <span class="liulan"><?php echo $list["click_count"]; ?></span>
                                            </div>
                                        </div>
                                    </a>
                                </li>
                            <?php endforeach; ?>
                            <?php endif; ?>
                        </ul>
                        <!-- 分页开始 -->
                        <div class="tcdPageCode">
                            <?php echo $pager;?>
                        </div>
                        <!-- 分页结束 -->
                    </div>
                      
                </div>
                <div class="common-layout-right box">
                    <div class="hot_news_block">
                        <h1 class="box">热门标签</h1>
                        <div class="hot_label_tag box">
                            <ul>
                                <?php
                                if(!empty($cates)):
                                foreach($cates as  $list):
                                ?>
                                <a href="news.php?cate_id=<?php echo $list["cate_id"]; ?>">
                                    <li <?php if($list["cate_id"] == $cateId):?> class="act" <?php endif; ?>><?php echo $list["cate_name"]; ?></li>
                                </a>
                                <?php endforeach; ?>
                                <?php endif; ?>
                            </ul>
                        </div>
                    </div>
                    <div class="hot_news_block ">
                        <h1 class="box">热门咨讯</h1>
                        <div class="hot_news_tag box">
                            <ul>
                                <?php
                                if(!empty($hotNews)):
                                foreach($hotNews as $key => $list):
                                ?>
                                    <li>
                                        <a style="display: inherit;" href="/new/newsdetail.php?id=<?php echo $list['article_id'];?>" title="<?php echo $list['title'];?>">
                                            <p class="tit many_line line_two"><?php echo $list['title'];?></p>
                                            <div class="hot_news_tip">
                                                
                                                <span class="time"><?php echo $list['update_tm'];?></span>
                                                <span class="liulan"><?php echo $list['click_count'];?></span>
                                            </div>
                                        </a>
                                    </li>
                                <?php endforeach; ?>
                                <?php endif; ?>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
<?php include('./footer.php');?>